import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';

// createWebHistory
// import Layout from '@/layout/Layout.vue';
import { commonAfterHook } from './hook/after/common';
import { commonBeforeHook } from './hook/before/common';
import { setTitleHook } from './hook/before/setTitle';
// const routeFiles = require.context('@/router/modules', false, /\.ts|\.js$/);
const authImportRoutes: RouteRecordRaw[] = [];

// routeFiles.keys().forEach((fileName) => {
//     authImportRoutes.push(...routeFiles(fileName).routes);
// });

// console.info('动态路由列表', authImportRoutes);

export const asyncRoutesList: RouteRecordRaw[] = [...authImportRoutes];

export const constantRoutes: RouteRecordRaw[] = [
    // {
    //     path: '/redirect',
    //     component: Layout,
    //     meta: { hidden: true },
    //     children: [
    //         {
    //             path: '/redirect/:path(.*)',
    //             component: () => import('@/views/redirect/index.vue'),
    //         },
    //     ],
    // },
    // {
    //     path: '/login',
    //     component: () => import('@/views/login/index.vue'),
    //     meta: { hidden: true },
    // },
    {
        path: '/',
        name: '/',
        component: () => import('@/views/home/index.vue'),
        redirect: '/index',
        children: [
            {
                path: 'index',
                name: 'index',
                meta: {
                    title: '首页',
                    icon: 'homepage',
                    affix: true,
                    keepAlive: true,
                    alwaysShow: false,
                },
                component: () => import('@/views/home/index.vue'),
            },
        ],
    },
    {
        path: '/XYGContainer',
        name: 'XYGContainer',
        component: () => import('@/views/homePage/index.vue'),
        // redirect: '/',
        children: [
            {
                path: 'XYGContainer',
                name: 'XYGContainer',
                meta: {
                    title: '首页',
                    icon: 'homepage',
                    affix: true,
                    keepAlive: true,
                    alwaysShow: false,
                },
                component: () => import('@/views/homePage/index.vue'),
            },
        ],
    },
    // ...authImportRoutes,
    // {
    //     path: '/404',
    //     component: () => import('@/views/404/index.vue'),
    //     meta: { hidden: true },
    // },
    // {
    //     path: '/:pathMatch(.*)*',
    //     redirect: '/404',
    // },
];

export const router = createRouter({
    history: createWebHashHistory(),
    routes: constantRoutes as RouteRecordRaw[],
    // 刷新时，滚动条位置还原
    scrollBehavior: () => ({ left: 0, top: 0 }),
});

commonBeforeHook(router);
setTitleHook(router);
commonAfterHook(router);

export default router;
